import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login.vue'
import store from "@/store";


Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'login',
        component: Login,
        meta: {
            title: '若梦管理系统'
        },
    },
    {
        path: '/login',
        name: 'login',
        hidden: true,
        meta: {
            title: '若梦管理系统'
        },
        component: () => import('@/components/login.vue'),

    },
    {
        path: '/manage',
        name: 'Manage',
        hidden: true,
        component: () => import('@/views/Manage.vue'),
        redirect:"/manage/home",
        children: [
            {
                path: 'home',
                name: 'Home',
                hidden: true,
                component: () => import('@/views/Home.vue'),
                meta: {
                    title: '首页'
                }
            },
            {
                path: 'user',
                name: 'User',
                hidden: true,
                component: () => import('@/views/User.vue'),
                meta: {
                    title: '用户管理'
                }
            },

        ]
    },
    {
        path: '/test',
        name: 'test',
        hidden: true,
        component: () => import('@/components/test.vue')
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to,from,next) =>{
    localStorage.setItem("currentRouteName",to.meta.title)
    store.commit("setPath")
    next()
})
export default router
